package org.jadestudio.home.dao;

import java.sql.SQLException;
import java.util.List;

import com.ibatis.sqlmap.client.SqlMapClient;


public class ArticleDao {
	private SqlMapClient sqlMapClient;
	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}
	
	
	/**
	 * 获取首页文章列表
	 */
	public List<java.util.Map> getHomePageArticleList() throws SQLException{
		return sqlMapClient.queryForList("article.getHomePageArticleList");
	}
	
	
	/*
	 * 获取文章类型列表
	 */
	public List<java.util.Map> getArticleTypeList() throws SQLException{
		return sqlMapClient.queryForList("article.getArticleTypeList");
	}
	
	
	
	/*
	 * 获取游戏筛选列表（含分页）
	 */
	public List<java.util.Map> getArticleList(String category,int pageindex,int pagesize) throws SQLException{
		java.util.Map map = new java.util.HashMap();
		map.put("category", category);
		map.put("startindex", (pageindex-1)*pagesize);
		map.put("endindex", pagesize);
		
		return sqlMapClient.queryForList("article.getArticleList", map);
	}	
	
	
	/*
	 * 获取文章筛选列表总页数
	 */
	public int getArticlePageCount(String category,int pagesize) throws SQLException{
		java.util.Map map = new java.util.HashMap();
		map.put("category", category);
		map.put("pagesize", pagesize);
		
		Object result = sqlMapClient.queryForObject("article.getArticlePageCount", map);
		return (Integer)result;
	}
	

	/*
	 * 获取指定搜索关键字文章（前12个）
	 */
	public List<java.util.Map> searchArticlesByKeyname(String keyname) throws SQLException{
		return sqlMapClient.queryForList("article.searchArticlesByKeyname", keyname);
	}
	
	
	/*
	 * 获取文章详情BY ID
	 */
	public java.util.Map getArticleDetail(String id) throws SQLException{
		return (java.util.Map)sqlMapClient.queryForObject("article.getArticleDetail", id);
	}
	
	
	/*
	 * 获取文章相关游戏BY ID
	 */
	public List<java.util.Map> getArticleGameList(String id) throws SQLException{
		return sqlMapClient.queryForList("article.getArticleGameList", id);
	}
	
	
	/*
	 * 获得文章投票情况BY ID
	 */
	public List<java.util.Map> getArticleVotes(String id, String ip) throws SQLException{
		java.util.Map map = new java.util.HashMap();
		map.put("article_id", id);
		map.put("ip", ip);
		return sqlMapClient.queryForList("article.getArticleVotes", map);
	}
	
	
	/*
	 * 文章投票
	 */
	public int voteArticle(String article_id,int score,String ip) throws SQLException{
		java.util.Map map = new java.util.HashMap();
		map.put("article_id", article_id);
		map.put("score", score);
		map.put("ip", ip);
		
		int result = (Integer)sqlMapClient.queryForObject("article.voteArticle", map);
		return result;
	}
	
	
	/*
	 * 获取相关文章列表
	 */
	public List<java.util.Map> getSimilarArticleList(String id) throws SQLException{
		return sqlMapClient.queryForList("article.getSimilarArticleList", id);
	}
}
